package pl.pawluk.inz.web.model;

import org.apache.commons.lang3.math.NumberUtils;
import org.primefaces.model.SelectableDataModel;
import pl.pawluk.inz.dto.BaseDTO;
import pl.pawluk.inz.dto.UserDTO;

import javax.faces.model.ListDataModel;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: mandp
 * Date: 01.05.13
 * Time: 20:18
 * To change this template use File | Settings | File Templates.
 */
public class SelectableListDataModel<T extends BaseDTO> extends ListDataModel<T> implements SelectableDataModel<T> {

    public SelectableListDataModel(List<T> list) {
        super(list);
    }

    @Override
    public Long getRowKey(T t) {
        return t.getId();  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public T getRowData(String s) {
        if (s != null && NumberUtils.isNumber(s)) {
            List<T> dtoList = (List<T>) getWrappedData();
            return dtoList.get(Integer.parseInt(s));
        }
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }
}
